package com.sam.im.heiqun.uis.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sam.im.heiqun.R;
import com.sam.im.heiqun.entities.ImFriendEntivity;
import com.sam.im.heiqun.uis.adapters.holder.SearchFriendHolder;
import com.yuyh.library.utils.GlideUtils;

import java.util.List;

/**
 * Created by Joe on 2016/12/25.
 */

public class SearchFriendAdpter extends RecyclerView.Adapter<SearchFriendHolder> {

    private Context context;
    private List<ImFriendEntivity> mGroupEntivities;
    private SearchFriendListClickListener mItemClickListener;

    public SearchFriendAdpter(Context context, List<ImFriendEntivity> groupEntivities) {
        this.context = context;
        this.mGroupEntivities = groupEntivities;
    }
    public SearchFriendAdpter(Context context) {
        this.context = context;
    }

    public void refresh( List<ImFriendEntivity> groupEntivities) {
        this.mGroupEntivities = groupEntivities;
        notifyDataSetChanged();
    }

    public interface SearchFriendListClickListener {
        void onSearchItemClick(View view, int position);
    }

    public void setItemClickListener(SearchFriendListClickListener mItemClickListener) {
        this.mItemClickListener = mItemClickListener;
    }

    @Override
    public SearchFriendHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_search_friend, parent, false);
        return new SearchFriendHolder(view, mItemClickListener);
    }

    @Override
    public void onBindViewHolder(SearchFriendHolder holder, int position) {
        GlideUtils.loadHeadCircularImage(context, mGroupEntivities.get(position).getHeadUrl(), holder.head_image);
        holder.nick.setText(mGroupEntivities.get(position).getName());
        holder.sign.setText(mGroupEntivities.get(position).getSign());
    }

    @Override
    public int getItemCount() {
        return mGroupEntivities != null ? mGroupEntivities.size() : 0;
    }
}